package exilim.exf1.cspacker.util;

import java.awt.Component;
import java.awt.Container;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;

/**
 * 
 * @author Janos
 * @version 15.08.2010 | 21:39:17
 * 
 */
public class SwingUtil {

	public static void addComponent(final Container cont, final GridBagLayout gbl, final Component c, final int x, final int y,
			final int width, final int height, final double weightx, final double weighty) {
		addComponent(cont, gbl, c, x, y, width, height, weightx, weighty, GridBagConstraints.NORTH, GridBagConstraints.BOTH);
	}

	public static void addComponent(final Container cont, final GridBagLayout gbl, final Component c, final int x, final int y,
			final int width, final int height, final double weightx, final double weighty, final int anchor, final int fill) {
		addComponent(cont, gbl, c, x, y, width, height, weightx, weighty, anchor, fill, new Insets(0, 0, 0, 0));
	}

	public static void addComponent(final Container cont, final GridBagLayout gbl, final Component c, final int x, final int y,
			final int width, final int height, final double weightx, final double weighty, final int anchor, final int fill,
			final Insets insets) {
		final GridBagConstraints gbc = new GridBagConstraints();
		gbc.fill = fill;
		gbc.gridx = x;
		gbc.gridy = y;
		gbc.gridwidth = width;
		gbc.gridheight = height;
		gbc.weightx = weightx;
		gbc.weighty = weighty;
		gbc.anchor = anchor;
		gbc.insets = insets;
		gbl.setConstraints(c, gbc);
		cont.add(c);
	}

	public static void setEnabledForChildren(final Container container, final boolean bEnabled) {

		for (int i = 0; i < container.getComponentCount(); i++) {
			final Component child = container.getComponent(i);
			child.setEnabled(bEnabled);
		}

	}

}
